package com.carassistant.beta.phone;

import android.app.TabActivity;
import android.content.ContentValues;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.TextView;

import com.carassistant.beta.R;
import com.carassistant.beta.common.AppManager;
import com.carassistant.beta.db.DBDao;
import com.carassistant.beta.db.DBData;

public class PhoneMainActivity extends TabActivity {
	public static final String TAG = "PhoneMainActivity";
	private RadioGroup mTabButtonGroup;
	private TabHost mTabHost;
	private ImageButton backBtn;
	private TextView titleTv;

	public static final String TAB_KEYPAD = "KEYPAD_ACTIVITY";
	public static final String TAB_RECORD = "RECORD_ACTIVITY";
	public static final String TAB_CONTACT = "CONTACT_ACTIVITY";
	public static final String TAB_FAV = "FAV_ACTIVITY";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.phone_main);
		AppManager.getInstance().addActivity(this);
		initView();
	}

	private void initView() {
		mTabHost = getTabHost();
		mTabButtonGroup = (RadioGroup) findViewById(R.id.home_radio_button_group);
		backBtn = (ImageButton) findViewById(R.id.back_home_btn);
		titleTv = (TextView) findViewById(R.id.titleTv);
		backBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				AppManager.getInstance().backHomeActivity();
			}
		});

		Intent i_keypad = new Intent(this, PhoneKeypadActivity.class);
		Intent i_record = new Intent(this, PhoneRecordActivity.class);
		Intent i_contact = new Intent(this, PhoneContactActivity.class);
		Intent i_fav = new Intent(this, PhoneFavActivity.class);

		mTabHost.addTab(mTabHost.newTabSpec(TAB_KEYPAD).setIndicator(TAB_KEYPAD)
				.setContent(i_keypad));
		mTabHost.addTab(mTabHost.newTabSpec(TAB_RECORD)
				.setIndicator(TAB_RECORD).setContent(i_record));
		mTabHost.addTab(mTabHost.newTabSpec(TAB_CONTACT)
				.setIndicator(TAB_CONTACT).setContent(i_contact));
		mTabHost.addTab(mTabHost.newTabSpec(TAB_FAV).setIndicator(TAB_FAV)
				.setContent(i_fav));
		
		mTabHost.setCurrentTabByTag(TAB_KEYPAD);
		titleTv.setText("拨号");

		mTabButtonGroup
				.setOnCheckedChangeListener(new OnCheckedChangeListener() {
					public void onCheckedChanged(RadioGroup group, int checkedId) {
						switch (checkedId) {
						case R.id.phone_keypad:
							mTabHost.setCurrentTabByTag(TAB_KEYPAD);
							titleTv.setText("拨号");
							break;

						case R.id.phone_record:
							mTabHost.setCurrentTabByTag(TAB_RECORD);
							titleTv.setText("通话记录");
							break;

						case R.id.phone_contact:
							mTabHost.setCurrentTabByTag(TAB_CONTACT);
							titleTv.setText("所有联系人");
							break;

						case R.id.phone_fav:
							mTabHost.setCurrentTabByTag(TAB_FAV);
							titleTv.setText("收藏夹");
							break;

						default:
							break;
						}
					}
				});
	}
}
